package com.yun.algorithmproblem.leetcode;

import java.util.Arrays;

public class Leetcode1561 {
    public static void main(String[] args) {
        Leetcode1561 obj = new Leetcode1561();
        int[] piles = new int[]{9,8,7,6,5,1,2,3,4};
        System.out.println(obj.maxCoins(piles));
    }


    public int maxCoins(int[] piles) {
        Arrays.sort(piles);
        int length = piles.length;
        int ans = 0;
        int cnt = 0;
        while (cnt != length / 3) {
            ans += piles[length - 2 - cnt * 2];
            cnt++;
        }
        return ans;
    }
}
